 @extends('layouts.admin_common') @section('content')
<div class="breadcrumbs_container">{{
	Breadcrumbs::render('admin.category_master') }}</div>
<div class="system_tab_line"></div>
<script>
    function onSubmit(op,categoryID){
 	   document.getElementById('category_id').value=categoryID;
 	 	   {
                var form = document.getElementById('cateory');
                form.action="category/"+op;
                form.submit();
 	 	   }
        }

    function onSubmitDel(op,categoryID){
  	   document.getElementById('category_id').value=categoryID;
  	   if (false === confirm('削除しますか？') )return;

  	 	   {
                 var form = document.getElementById('cateory');
                 form.action="category/"+op;
                 form.submit();
  	 	   }
         }

    function onSubmitCsv(op,categoryID){
    	     document.getElementById('category_id').value=categoryID;

             var form = document.getElementById('cateory');
             form.action="category/"+op;
             form.submit();

    }

    function reBack(){
    		window.location.href=('../home');
        }

    function addCategory(){
    	//var tblhtml = $("#add_cateory").html();
    	var tblhtml ="";
    	var cnt = parseInt($("#rec_num").val())+1;
     	//var tblhtml=tbl.innerHTML;
     	tblhtml += "<tr><td><input type='hidden' name='category_id_'" +(cnt-1)+ " value='' > ";
     	tblhtml += "<input type='text' style='width:100%' class='form-control' placeholder='' name='category_code_"+(cnt-1)+"'></td><td>";
     	tblhtml += "<input type='text' style='width:100%' class='form-control' placeholder='' ";
     	tblhtml += "name='category_name_"+(cnt-1)+"'></td><td><input type='text' style='width:100%' class='form-control' placeholder='' ";
     	tblhtml += "name='category_en_"+(cnt-1)+"'></td><td><input type='text' style='width:100%' class='form-control' placeholder='' ";
     	tblhtml += "name='category_image_"+(cnt-1)+"' style='width:100%' ></td><td>&nbsp;</td></tr>";

     	$("#add_cateory").append(tblhtml);
     	$("#rec_num").val(cnt);
    }

    function remove(temp){
    	$(temp).parent().parent().remove();
    }
    </script>

<form class="form-inline" id="cateory" method="post"
	enctype="multipart/form-data">
	<table class="table table-bordered" style="width: 100%;" id="add_cateory">
		<tr>
			<td>コード</td>
			<td>カテゴリー名</td>
			<td>英語表記</td>
			<td>画像</td>
		</tr>
		<?php if(!empty($categoryInfos)):?>
		<?php
    for ($i = 0; $i < count($categoryInfos); $i ++) :
        $categoryInfo = $categoryInfos[$i];
        ?>
		<tr>
			<td><input type="hidden" class="form-control" placeholder=""
				style="width: 100%;" name="category_id_{{$i}}" style='width:100%'
				value="{{$categoryInfo->category_id}}"> <input type="text"
				class="form-control" placeholder="" name="category_code_{{$i}}"
				style='width: 100%' value="{{$categoryInfo->category_code}}"></td>
			<td><input type="text" class="form-control" placeholder=""
				name="category_name_{{$i}}" style='width: 100%'
				value="{{$categoryInfo->category_name}}"></td>
			<td><input type="text" class="form-control" placeholder=""
				name="category_en_{{$i}}" style='width: 100%'
				value="{{$categoryInfo->category_en}}"></td>
			<td><input type="text" class="form-control" placeholder=""
				name="category_image_{{$i}}" style='width: 100%'
				value="{{$categoryInfo->category_image}}"></td>
			<td><input type="button" value="削除"
				class="btn btn-primary button_normal"
				onclick="onSubmitDel('delete','{{$categoryInfo->category_id}}')"></td>
		</tr>
		<?php endfor;?>
		<?php endif;?>
	</table>


	<input type="hidden" id="rec_num" name="rec_num"
		value="{{count($categoryInfos)}}" />
	<table class="table table-condensed">
		<tr>
			<td><input type="button" value="保存"
				class="btn btn-primary button_normal" onclick="onSubmit('save')" /></td>
			<td><input type="button" value="キャンセル"
				class="btn btn-primary button_normal" onclick="reBack()" /></td>
			<td><button id="button_add_cateory" type="button"
					onclick="addCategory();"
					class="pure-button pure-button-primary button_normal">@lang('messages.add_category')</button>
			</td>
			<td><label for="sample1" class="btn btn-primary button_normal">Csv取込
					<input type="file" name="csv_file" id="sample1"
					style="display: none;" class="btn btn-primary button_normal"
					onChange="onSubmitCsv('csv')" />
			</label></td>
		</tr>
	</table>
	<input type="hidden" name="_token" id="csrf-token"
		value="{{ Session::token() }}" /> <input type="hidden"
		id="category_id" name="category_id">
</form>
@endsection

